package com.zmn.plat.admin.controller.push;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.zmn.common.dto2.ResponseDTO;
import com.zmn.mcc.cas.model.LoginStaff;
import com.zmn.mcc.cas.web.StaffAdminService;

import lombok.extern.slf4j.Slf4j;

/**
 * 描述: 站内信修改控制器
 *
 * @author linfeng
 * @since 2020/5/21
 **/
@Slf4j
@RestController
@RequestMapping(value = "/push/inner/")
public class PushInnerModifyController extends PushInnerBaseController {

    /**
     * 设置消息为已读或者暂存
     * 
     * @param innerId
     * @return
     */
    @RequestMapping(value = "read")
    public ResponseDTO<String> read(@RequestParam(value = "innerId", defaultValue = "0") Integer innerId,
        @RequestParam(value = "status", defaultValue = "0") Integer status) {
        try {
            pushInfoService.updateOneInnerMsg(innerId, status);
            return ResponseDTO.success("操作成功！");
        } catch (Exception e) {
            log.error("[{}],设置消息已读/暂存失败，msg:{}", TAG, e.getMessage(), e);
            return ResponseDTO.fail("操作失败，请联系管理员！");
        }
    }

    /**
     * 设置该员工所有未读消息为暂存状态
     * 
     * @return
     */
    @RequestMapping(value = "setMsgTemporaryStorage")
    public ResponseDTO<String> setMsgTemporaryStorage() {
        try {
            LoginStaff staff = StaffAdminService.currentStaff();
            pushInfoService.updateInnerMsgTemporaryStorageByStaffId(staff.getStaffId());
            return ResponseDTO.success("操作成功！");
        } catch (Exception e) {
            log.error("[{}],设置未读消息暂存失败，msg:{}", TAG, e.getMessage(), e);
            return ResponseDTO.fail("操作失败，请联系管理员！");
        }
    }
}
